﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BEGDC.Utility.Castle;
namespace BEGDC.CC.Web.Workflow
{
	/// <summary>
	/// Summary description for FlowSearch.
	/// </summary>
	public class FlowSearch : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtAppNo;
		protected System.Web.UI.WebControls.DataGrid DG_ActionLog;
		protected System.Web.UI.WebControls.Button btnSearch;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
			}
		}


		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			string sql = "SELECT     al.ActionLogID AS Id, (CASE isnull(al.mybackup, '') WHEN '' THEN al.Actor ELSE al.Actor + '(' + e.nameen + ')' END) AS Actor, sp.StepName AS Step,                       a.ActionName AS Action, al.ActionDate, al.Comment FROM         ActionLog AS al INNER JOIN    Action AS a ON al.Action = a.ActionID INNER JOIN       Step AS sp ON al.SourceStep = sp.StepID INNER JOIN      Employee AS e ON al.Actor = e.NameEN INNER JOIN   Application ON al.AppID = Application.AppID WHERE     (Application.AppNo = '{0}') union SELECT     Id, COALESCE (Actor, Owner) AS Actor, StepCode, Action, ActionDate, Comment FROM         ( SELECT     99999 AS Id, Employee.NameEN AS Actor, CASE FlowInstance.CurrentActiveOwner WHEN 'N/A' THEN '' ELSE CurrentActiveOwner END AS Owner,   Step.StepCode, '' AS Action, NULL AS ActionDate, '' AS Comment FROM         FlowInstance INNER JOIN    Step ON FlowInstance.CurrentActiveStep = Step.StepID INNER JOIN     Application ON FlowInstance.AppID = Application.AppID LEFT OUTER JOIN  Employee ON FlowInstance.CurrentActiveOwner = Employee.EmployeeNo WHERE     (Application.AppNo = '{0}')) AS a";

			sql = sql.Replace("{0}", this.txtAppNo.Text);

			BEGDC.CC.BL.AdvancedSearch.IAdvancedSearch QueryService = AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.SearchService] as BEGDC.CC.BL.AdvancedSearch.IAdvancedSearch;
			DataTable ActionLogTable = QueryService.QueryList(sql);
			this.DG_ActionLog.DataSource = ActionLogTable;
			this.DG_ActionLog.DataBind();
		}
	}
}
